package com.example.wheresmystuff2;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * This class represents the first page after a user successfully signs in. 
 * @author Team 26
 */
public class SuccessfulSignIn extends Activity {
	Database db;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.successful_sign_in);
	    
	    db = new Database(this);
	    db.open();
	    
	    String current_User=LogIn.getCurrentUser(); //Current user's username
	    ArrayList<Object> currUserData = db.getUserRowAsArray(current_User); //Current user's information
	    
	    //These are the buttons on screen.
	    Button addItem = (Button) findViewById(R.id.succ_sign_in_add_item); 
	    Button goToGallery = (Button) findViewById(R.id.succ_sign_in_gallery);
	    Button editUser = (Button) findViewById(R.id.succ_sign_in_user_list);
	    
	    //If the user is an admin, the editUser button is made visible.
	    int userIsAdmin = (Integer) currUserData.get(5);
	    if(userIsAdmin == 1){
	    	editUser.setVisibility(View.VISIBLE);
	    }
	    
	    db.close();
	    //addItem button goes to AddLostItem activity
	    addItem.setOnClickListener(new OnClickListener()
	    {
	    	public void onClick(View v){
	    		Intent myIntent = new Intent(SuccessfulSignIn.this, AddItem.class);
	    		SuccessfulSignIn.this.startActivity(myIntent);
	    	}
	    });
	    
	    //goToGallery button goes to Gallery activity
	    goToGallery.setOnClickListener(new OnClickListener()
	    {
	    	public void onClick(View v){
	    		Intent myIntent = new Intent(SuccessfulSignIn.this, Gallery.class);
	    		SuccessfulSignIn.this.startActivity(myIntent);
	    	}
	    });
	    
	    //editUser button goes to EditUser Activity
	    editUser.setOnClickListener(new OnClickListener()
	    {
	    	public void onClick(View v){
	    		Intent myIntent = new Intent(SuccessfulSignIn.this, EditUser.class);
	    		SuccessfulSignIn.this.startActivity(myIntent);
	    	}
	    });
	}
}
